const { opendir,readFile,writeFile,copyFile  } =require('fs/promises');
const path = require('path');

async function main(){
    try {
        const dir = await opendir('./');
        for await (const dirent of dir)
        if(dirent.name.indexOf('ZTE')!==-1) {
          const context = await readFile(`./${dirent.name}`) 
          let arr = context.toString().split('\r\n')
          while(arr.findIndex(item=>item.endsWith('#$exit')||item.endsWith('#$exit\r\n'))!==-1){
            let index = arr.findIndex(item=>item.endsWith('#$exit')||item.endsWith('#$exit\r\n'))
            arr.splice(index ,1);
          }
          await writeFile(`./${dirent.name}`,arr.join('\r\n'))

        }
        
      } catch (err) {
        console.error(err);
      }
}

main();